package cn.animal.api.config;

import cn.animal.common.utils.UserContext;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Bean;

public class DefaultFeignConfig {

    // 后续获取用户信息的关键字
    private static final String USERINFO_KEY = "user-info";

    @Bean
    public RequestInterceptor requestInterceptor() {
        return new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate requestTemplate) {
                String context = UserContext.getContext();
                requestTemplate.header(USERINFO_KEY, context);
            }
        };
    }

}
